from common.conmysql import db
from common.read import read
from common.YamlUtil import YamlUtil
#从配置文件中读取登录手机号
def get_mobile():
    mobile = read.read_yaml()["login_fixture"]["username"]
    return mobile

#数据库查看登录用户的收货地址
def get_addressid():
    address_id = YamlUtil().read_extra_yaml()["address_id"]
    sql = f"select count(1) from user_operation_useraddress where id={address_id}; "
    result = db.select_db(sql)
    return result

#数据库删除收货地址
def delete_address():
    address_id = YamlUtil().read_extra_yaml()["address_id"]
    sql = f"delete from user_operation_useraddress where id={address_id}; "
    db.delete_info(sql)


#数据库查看用户收藏id
def get_userfavid():
    goodsid_id = read.read_yaml()["goodsid"]
    mobile = get_mobile()
    sql = f"select id from user_operation_userfav where goods_id={goodsid_id} and user_id=(select id from `users_userprofile` where mobile = {mobile} );"
    result = db.select_db(sql)
    return result
#数据库查看用户收藏id总数
def get_userfav_all():
    mobile = get_mobile()
    sql = f"select count(1) from user_operation_userfav where  user_id=(select id from `users_userprofile` where mobile = {mobile} );"
    result = db.select_db(sql)
    return result

#数据库删除用户收藏id
def delete_userfav():
    mobile = get_mobile()
    sql = f"delete from user_operation_userfav where  user_id=(select id from `users_userprofile` where mobile = {mobile} );"
    db.delete_info(sql)


#数据库查获取验证码
def get_code(mobile):
    sql = f"select code from users_verifycode where mobile = {mobile} order by id desc limit 1;"
    result = db.select_db(sql)
    return result

#删除注册的用户数据
def delete_user(mobile):
    sql = "delete from users_userprofile where mobile = '%s';" % mobile
    db.delete_info(sql)

#删除已发送验证码数据：
def delete_code(mobile):
    sql = "delete from users_verifycode where mobile = '%s';" % mobile
    db.delete_info(sql)

#查询banner数量
def banner_num():
    sql = "select count(1) as banner_num from goods_banner;"
    result = db.select_db(sql)
    return result

#查询我的留言数量
def messages_id():
    mobile = get_mobile()
    sql = f"SELECT count(1) FROM `user_operation_userleavingmessage` where user_id= (select id from `users_userprofile` where mobile = {mobile} );"
    result = db.select_db(sql)
    return result

#删除用户的留言信息
def delete_message():
    mobile = get_mobile()
    sql = f"DELETE FROM `user_operation_userleavingmessage` where user_id= (select id from `users_userprofile` where mobile = {mobile} );"
    db.delete_info(sql)

#查看用户id
def get_userid(mobile):
    sql = f"select id from `users_userprofile` where mobile = {mobile} ;"
    result = db.select_db(sql)
    return result


